/* -----------------------------------------------------------------------------
*  CFileTxtOut
*  Author: Antonio Javier Gallego Sánchez (ajgallego AT gmail DOT com)
*  License: GNU Public License
* ----------------------------------------------------------------------------*/

#include "CFileTxtOut.hpp"

#include <iostream>
#include <fstream>
#include <string.h>

#include "CVectorString.hpp"
#include "asrtbas.h"
using namespace std;

struct prv_fileOut_t
{
    ofstream file;
};

//------------------------------------------------------------------------------
//
static struct prv_fileOut_t* prv_create()
{
    prv_fileOut_t *data = new prv_fileOut_t;
    assert_no_null( data );

    return data;
}

//------------------------------------------------------------------------------
//
CFileTxtOut :: CFileTxtOut( const char* filename )
{
    m_data = prv_create();

    m_data->file.open( filename, ios::out );

    assert( m_data->file.fail() == false &&
            "There was an error opening the file" );
}

//------------------------------------------------------------------------------
//
CFileTxtOut :: ~CFileTxtOut()
{
    m_data->file.close();

    delete m_data;
}

//------------------------------------------------------------------------------
//
void CFileTxtOut :: writeChar( char c )
{
    m_data->file << c;
}

//------------------------------------------------------------------------------
//
void CFileTxtOut :: writeString( const char* str )
{
    m_data->file << str;
}

//------------------------------------------------------------------------------
//
void CFileTxtOut :: writeBool( bool value )
{
    m_data->file << value;
}

//------------------------------------------------------------------------------
//
void CFileTxtOut :: writeInt( int value )
{
    m_data->file << value;
}

//------------------------------------------------------------------------------
//
void CFileTxtOut :: writeUInt( unsigned int value )
{
    m_data->file << value;
}

//------------------------------------------------------------------------------
//
void CFileTxtOut :: writeDouble( double value )
{
    m_data->file << value;
}

//------------------------------------------------------------------------------
//
void CFileTxtOut :: writeVector( const class CVectorString *content )
{
    unsigned int size = content->size();

    for( unsigned int i = 0; i < size; ++i )
    {
        this->writeString( content->get( i ) );

        if( i < size - 1 )
            this->writeChar( '\n' );
    }
}

/**
*/